package com.anti.modular.bus.buscostincomeexpenses.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.commom.api.Result;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.bus.buscostincomeexpenses.param.BusCostIncomeExpensesParam;
import com.anti.modular.bus.buscostincomeexpenses.service.BusCostIncomeExpensesService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 收入支出配置控制器
 *
 * @author anti
 * @date 2021-04-08 14:15:30
 */
@RestController
@RequestMapping("busCostIncomeExpenses")
public class BusCostIncomeExpensesController {

    @Resource
    private BusCostIncomeExpensesService busCostIncomeExpensesService;

    /**
     * 查询收入支出配置
     *
     * @author anti
     * @date 2021-04-08 14:15:30
     */
    @GetMapping("page")
    public Result page(PageParam pageParam, BusCostIncomeExpensesParam busCostIncomeExpensesParam) {
        return Result.data(busCostIncomeExpensesService.page(pageParam,busCostIncomeExpensesParam));
    }

    /**
     * 查询收入支出配置树
     *
     * @author anti
     * @date 2021-04-08 14:15:30
     */
    @GetMapping("tree")
    public Result tree(BusCostIncomeExpensesParam busCostIncomeExpensesParam) {
        return Result.data(busCostIncomeExpensesService.tree(busCostIncomeExpensesParam));
    }
    /**
     * 添加收入支出配置
     *
     * @author anti
     * @date 2021-04-08 14:15:30
     */
    @PostMapping("add")
    @BusinessLog(title = "收入支出配置_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(BusCostIncomeExpensesParam.add.class) BusCostIncomeExpensesParam busCostIncomeExpensesParam) {
            busCostIncomeExpensesService.add(busCostIncomeExpensesParam);
        return Result.success("新增成功");
    }

    /**
     * 删除收入支出配置
     *
     * @author anti
     * @date 2021-04-08 14:15:30
     */
    @PostMapping("delete")
    @BusinessLog(title = "收入支出配置_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(BusCostIncomeExpensesParam.delete.class) BusCostIncomeExpensesParam busCostIncomeExpensesParam) {
            busCostIncomeExpensesService.delete(busCostIncomeExpensesParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑收入支出配置
     *
     * @author anti
     * @date 2021-04-08 14:15:30
     */
    @PostMapping("edit")
    @BusinessLog(title = "收入支出配置_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(BusCostIncomeExpensesParam.edit.class) BusCostIncomeExpensesParam busCostIncomeExpensesParam) {
            busCostIncomeExpensesService.edit(busCostIncomeExpensesParam);
        return Result.success("修改成功");
    }

    /**
     * 查看收入支出配置
     *
     * @author anti
     * @date 2021-04-08 14:15:30
     */
    @GetMapping("detail")
    public Result detail(@Validated(BusCostIncomeExpensesParam.detail.class) BusCostIncomeExpensesParam busCostIncomeExpensesParam) {
        return Result.data(busCostIncomeExpensesService.detail(busCostIncomeExpensesParam));
    }

    /**
     * 收入支出配置列表
     *
     * @author anti
     * @date 2021-04-08 14:15:30
     */
    @GetMapping("list")
    public Result list(BusCostIncomeExpensesParam busCostIncomeExpensesParam) {
        return Result.data(busCostIncomeExpensesService.list(busCostIncomeExpensesParam));
    }
    @GetMapping("getListByType/{type}")
    public Result getListByType(@PathVariable(name = "type") Integer type) {
        return Result.data(busCostIncomeExpensesService.getListByType(type));
    }
}
